package top.atcra.rpc.demo.globalTest;

import cn.hutool.core.util.RandomUtil;
import top.atcra.rpc.RPCBootstrap;
import top.atcra.rpc.demo.DemoApi;
import top.atcra.rpc.service.ReferenceConfig;

public class SingleClientMain {
    public static void main(String[] args) {
        System.out.println("客户端启动");
        var client = new RPCBootstrap(RPCBootstrap.Role.CLIENT);
        var reference = new ReferenceConfig<>("demoService", "demo1", DemoApi.class);
        client.reference(reference);
        var proxy = reference.getProxy();
        System.out.println(proxy.sayHello("atcra.proxy started."));
        while(true) {
            try{
                proxy.sayHello(RandomUtil.randomNumbers(6));
            }catch (Exception e) {
                System.out.println("发生错误: "+e.getMessage());
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
//        client.shutdown();
    }
}
